﻿/// ---------------------------------------------
///
/// ---------------------------------------------

///---------------------------

//双击事件
function CustomDbClick() {
    parent.closeWin(); //去掉双击功能

}

//添加信息
var fnCustomAdd = function () {
    alert("不能新增!");
    return;
}

//修改信息
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var IsValidate = record._oData["IsValidate"]
    if (IsValidate == "Y") {
        alert("已确认记录不能修改");
        return;
    }

    //debugger;
    const_EditEntity = "wkWorkResult";
    var pagetitle = "修改-" + record._oData["CName"] + "-" + record._oData["WorkDate"] + "-考勤记录";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&fun=edit" + "&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;

}

//保存成功回调，更新考勤确认表中的符号
var CallBack = function () {
    //debugger
    var elist = [];
    elist.push(record._oData["EmployeeID"]);
    elist.push(record._oData["WorkDate"]);
    elist.push(record._oData["WkStatus"]);

    YAHOO.util.Connect.asyncRequest('POST', "../EHR/workTimeAjax.aspx?flag=updateconfirmworkresult&json=" + encodeURI(elist.join(",")), {
        success: function (res) {
            try {
                var str = res.responseText;
                //debugger;
                if (str == "1") {
                    alert("考勤确认报表更新成功！");
                }
                else {
                    alert("考勤确认报表更新失败！");
                }
            }
            catch (e) { }
            finally { }
        },
        failure: function (error) {
            alert("数据错误：" + error.statusText);
        }
    }, null);

}

//删除
var fnCustomDelete = function () {
    alert("删除无效!");
    return;
}

//确认考勤记录
var fnConfirmData = function () {
    //debugger
    //保存列表
    //Save("setworkResult");
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        //this.getRecordSet()._records[0]._oData["BarItem"]
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData[const_entityID]);
            dl.push(list[i]._sId); //获取行ID；
        }
    }
    if (elist.length > 0) {
       var SaveUrl = "AjaxData/DataSave.aspx?r=" + Math.random() + "&action=confirmWorkResult&entity=" + const_EditEntity + "&json=" + elist.join(",");
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        alert("数据确认成功");
                    }
                    else {
                        alert(str + "\n" + "数据确认失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("确认失败，数据错误：" + error.statusText);
            }
        }, null);
    }
    else {
        alert("没有选择记录！")
        return;
    }

    //刷新列表
    ReLoadData();
    //setTimeout(setcheckbox, 1000);
}

//隐藏列
function customFnHideCol() {
    //debugger;
    //myDataTable.hideColumn(parseInt(1));
    //myDataTable.refreshView();
};


function setcheckbox() {
    //debugger;
    //alert( $("#yuievtautoid-0 tr").eq(0).html());
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    dl = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["IsValidate"] == 'Y') {
            var tr = $("#yuievtautoid-0 tr").eq(i + 3);
            //alert(tr.html());
            //tr.find(":checkbox").attr("checked", true);
            tr.find(":checkbox").attr("disabled", true);
        }
    }

    //$("input[type='checkbox']").attr("disabled", true);
}

//导入
function fnImport() {
    document.getElementById("EditUIWindow").src = "../EHR/hrImportWorkResult.aspx";
    SetDWH(500, 350, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//初始化
if (typeof ($) != "undefined") {
    //debugger;
    $(document).ready(function () {
        //setTimeout(setcheckbox, 1000);
    });
}

